home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Chip 2011 November
/
CHIP_2011_11.iso
/
Programy
/
Inne
/
Gry
/
Carnage_Contest
/
scripts
/
CC Original
/
weapons
/
Bow.lua
< prev
next >
Wrap
Text File
|
2010-08-31
|
6KB
|
174 lines
--------------------------------------------------------------------------------
-- Weapon Bow + Projectile Arrow
-- Original Carnage Contest Weapon
-- Script by DC, August 2009, www.UnrealSoftware.de
--------------------------------------------------------------------------------
-- Setup Tables
if cc==nil then cc={} end
cc.bow={}
cc.bow.arrow={}
-- Load & Prepare Ressources
cc.bow.gfx_wpn0=loadgfx("weapons/bow0.bmp") -- Weapon Image Frame 0
setmidhandle(cc.bow.gfx_wpn0)
cc.bow.gfx_wpn1=loadgfx("weapons/bow1.bmp") -- Weapon Image Frame 1
setmidhandle(cc.bow.gfx_wpn1)
cc.bow.gfx_pro=loadgfx("weapons/arrow.bmp") -- Projectile Image
setmidhandle(cc.bow.gfx_pro)
cc.bow.sfx_attack=loadsfx("arrow_shoot.ogg") -- Attack Sound
cc.bow.sfx_impact=loadsfx("arrow_impact.ogg") -- Impact Sound
--------------------------------------------------------------------------------
-- Weapon: bow
--------------------------------------------------------------------------------
cc.bow.id=addweapon("cc.bow","Bow",cc.bow.gfx_wpn0,1) -- Add Weapon (1 use)
cc.bow.ammo=5 -- 5 arrows
function cc.bow.draw() -- Draw
setblend(blend_alpha)
setalpha(1)
setcolor(255,255,255)
if cc.bow.ammo-weapon_shots>0 and weapon_timer<=0 then
drawinhand(cc.bow.gfx_wpn1,6,0)
else
drawinhand(cc.bow.gfx_wpn0,6,0)
end
-- Arrow
if cc.bow.ammo-weapon_shots>0 and weapon_timer<=0 and getplayeraction(0)==0 then
setrotation(getplayerrotation(0))
setscale(getplayerdirection(0),1)
drawimage(cc.bow.gfx_pro,getplayerx(0)+7*getplayerdirection(0),getplayery(0)+3)
end
-- HUD ammobar
if cc.bow.ammo-weapon_shots>0 then
hudammobar(cc.bow.ammo-weapon_shots,cc.bow.ammo)
end
-- HUD Crosshair
if cc.bow.ammo-weapon_shots>0 then
hudcrosshair(7,3)
end
end
function cc.bow.attack(attack) -- Attack
-- Decrement timer
if weapon_timer>0 then
weapon_timer=weapon_timer-1
end
-- Attack
if weapon_shots<cc.bow.ammo and weapon_timer<=0 and attack==1 then
-- No more weapon switching!
useweapon(0)
-- Reset Timer
weapon_timer=30
-- Attack
playsound(cc.bow.sfx_attack)
weapon_shots=weapon_shots+1
id=createprojectile(cc.bow.arrow.id)
projectiles[id]={}
-- Ignore collision with current player at beginning
projectiles[id].ignore=playercurrent()
-- Set initial position of projectile
projectiles[id].x=getplayerx(0)+(7*getplayerdirection(0))-math.sin(math.rad(getplayerrotation(0)))*5.0
projectiles[id].y=getplayery(0)+3+math.cos(math.rad(getplayerrotation(0)))*5.0
-- Set speed of projectile
projectiles[id].sx=math.sin(math.rad(getplayerrotation(0)))*9.0
projectiles[id].sy=-math.cos(math.rad(getplayerrotation(0)))*9.0
-- Initial movement
projectiles[id].x=projectiles[id].x-projectiles[id].sx*1.0
projectiles[id].y=projectiles[id].y-projectiles[id].sy*1.0
for i=1,3,1 do
if cc.bow.arrow.move(id)==1 then
break
end
end
-- Effects
-- End Turn
if (weapon_shots>=cc.bow.ammo) then
endturn()
end
end
end
--------------------------------------------------------------------------------
-- Projectile: arrow
--------------------------------------------------------------------------------
cc.bow.arrow.id=addprojectile("cc.bow.arrow") -- Add Projectile
function cc.bow.arrow.draw(id) -- Draw
-- Setup draw mode
setblend(blend_alpha)
setalpha(1)
setcolor(255,255,255)
setscale(1,1)
-- Calculate projectile rotation
setrotation(math.deg(math.atan2(projectiles[id].sx,-projectiles[id].sy)))
-- Draw projectile
drawimage(cc.bow.gfx_pro,projectiles[id].x,projectiles[id].y)
-- Draw Arrow if out of Screen
outofscreenarrow(projectiles[id].x,projectiles[id].y)
end
function cc.bow.arrow.update(id) -- Update
-- Wind + Gravity influence on speed
projectiles[id].sx=projectiles[id].sx+getwind()*0.1
projectiles[id].sy=projectiles[id].sy+getgravity()*1.5
-- Move
cc.bow.arrow.move(id)
end
function cc.bow.arrow.move(id)
rot=math.deg(math.atan2(projectiles[id].sx,-projectiles[id].sy))
-- Move (in substep loop for optimal collision precision)
msubt=math.ceil(math.max(math.abs(projectiles[id].sx),math.abs(projectiles[id].sy))/3)
msubx=projectiles[id].sx/msubt
msuby=projectiles[id].sy/msubt
for i=1,msubt,1 do
projectiles[id].x=projectiles[id].x+msubx
projectiles[id].y=projectiles[id].y+msuby
-- Collision
if collision(col3x3,projectiles[id].x+math.sin(math.rad(rot))*8,projectiles[id].y-math.cos(math.rad(rot))*8)==1 then
if terraincollision()==1 or objectcollision()>0 or playercollision()~=projectiles[id].ignore then
if playercollision()~=0 then
-- Cause Player damage
playerpush(playercollision(),projectiles[id].sx/10.0,projectiles[id].sy/10.0)
playerdamage(playercollision(),7)
blood(projectiles[id].x+math.sin(math.rad(rot))*8,projectiles[id].y-math.cos(math.rad(rot))*8)
playsound(sfx_splatter3)
elseif objectcollision()>0 then
-- Cause Object damage
objectdamage(objectcollision(),7)
else
-- Draw Arrow in terrain
terrainimage(cc.bow.gfx_pro,projectiles[id].x,projectiles[id].y,0,rot)
end
-- Effects
playsound(cc.bow.sfx_impact)
particle(p_smoke,projectiles[id].x+math.sin(math.rad(rot))*8,projectiles[id].y-math.cos(math.rad(rot))*8)
particlefadealpha(0.006)
-- Free projectile
freeprojectile(id)
return 1
end
else
projectiles[id].ignore=0
end
-- Water
if (projectiles[id].y)>getwatery()+5 then
-- Effects
particle(p_waterhit,projectiles[id].x,projectiles[id].y)
if math.random(1,2)==1 then
playsound(sfx_hitwater2)
else
playsound(sfx_hitwater3)
end
-- Free projectile
freeprojectile(id)
return 1
end
end
end